"use strict";
var app = new Vue({
    el: "#app",
    data: {
        id: "",
        userId: "",
        data: {},
        bannerData: [],
        imageSrc: "/images/collect.png",
        txtDes: "收藏",
        is_collect: 0
    },
    created: function() {
        if (this.id = $.GetRequest().id,
        "" != $.getPara("userId")) {
            var e = $.getPara("userId");
            this.userId = e,
            $.setStorage("userId", e)
        } else if ($.getStorage("userId") && "" != $.getStorage("userId")) {
            e = parseInt($.getStorage("userId"));
            this.userId = e
        }
        this.getData()
    },
    methods: {
        getData: function() {
            var t = this;
            $.ajax({
                type: "GET",
                url: "/api/press/detail",
                data: {
                    id: t.id,
                    userId: this.userId
                },
                success: function(e) {
                    200 == e.code ? (t.data = e.data,
                    t.bannerData = JSON.parse(e.data.banner_img),
                    t.is_collect = e.data.is_collect,
                    1 == t.is_collect ? (t.imageSrc = "/images/collection-active.png",
                    t.txtDes = "已收藏") : (t.imageSrc = "/images/collect.png",
                    t.txtDes = "收藏"),
                    t.$nextTick(function() {
                        new Swiper(".swiper-container",{
                            autoplay: 3e3,
                            loop: !0,
                            pagination: ".swiper-pagination",
                            autoplayDisableOnInteraction: !1
                        })
                    })) : $.toast(e.msg, "text")
                },
                error: function() {
                    $.toast("加载失败，请重试", "text")
                }
            })
        },
        collect: function() {
            if (this.userId && 0 < this.userId) {
                var t = this;
                t.is_collect ? $.ajax({
                    type: "POST",
                    url: "/api/collect/cancelCollect",
                    data: {
                        userId: t.userId,
                        type: 5,
                        objectId: t.id
                    },
                    success: function(e) {
                        200 == e.code && (t.imageSrc = "/images/collect.png",
                        t.txtDes = "收藏",
                        t.is_collect = 0),
                        $.toast(e.msg, "text")
                    },
                    error: function() {
                        $.toast("收藏失败，请重试", "text")
                    }
                }) : $.ajax({
                    type: "POST",
                    url: "/api/collect/collect",
                    data: {
                        userId: t.userId,
                        type: 5,
                        objectId: t.id
                    },
                    success: function(e) {
                        200 == e.code && (t.imageSrc = "/images/collection-active.png",
                        t.txtDes = "已收藏",
                        t.is_collect = 1),
                        $.toast(e.msg, "text")
                    },
                    error: function() {
                        $.toast("收藏失败，请重试", "text")
                    }
                })
            } else
                /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) ? window.webkit.messageHandlers.appLogin.postMessage(null) : alert("PC浏览器-appLogin")
        },
        urlHref: function() {
            if (this.userId&& 0 < this.userId) {
                var e = {
                    title: "在线",
                    type: "liuyan"
                };
                e.url = "/PageClassify/html/LeaveWords/liuyan.html?pressId=" + this.id,
                0 < this.userId && (e.url = "/PageClassify/html/LeaveWords/liuyan.html?pressId=" + this.id + "&userId=" + this.userId),
                /(Android)/i.test(navigator.userAgent) ? jsAndroid.appPush(JSON.stringify(e)) : /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) ? window.webkit.messageHandlers.appPush.postMessage(e) : (window.location.href = e.url,
                alert("PC浏览器"))
            } else
                /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) ? window.webkit.messageHandlers.appLogin.postMessage(null) : alert("PC浏览器-appLogin")
        },
        toMobile: function(e) {
            var t = {};
            t.mobile = e,
            /(Android)/i.test(navigator.userAgent) ? jsAndroid.appMobile(JSON.stringify(t)) : /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) ? window.webkit.messageHandlers.appMobile.postMessage(t) : alert("请使用移动设备拨号！")
        }
    }
});
